package com.cc.config;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;

/**
 * @author 33314
 * @version 1.0
 * @description: TODO
 * @date 2025/6/21 14:31
 */
public class WebConfig extends AbstractAnnotationConfigDispatcherServletInitializer {
    @Override
    protected Class<?>[] getRootConfigClasses() {
        //        添加 DispatcherServlet 配置SpringConfig容器
        return new Class[]{SpringConfig.class};
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
//        添加 DispatcherServlet 配置SpringMVCConfig容器
        return new Class[]{SpringMVCConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
//        添加 DispatcherServlet 映射
        return new String[]{"/"};
    }
/** 
 * @description: 添加过滤器 防止 字符集 post 乱码问题
 * @param:  
 * @return: javax.servlet.Filter[] 
 * @author 33314
 * @date: 2025/6/21 14:36
 */ 
    @Override
    protected Filter[] getServletFilters() {
        CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter();
        characterEncodingFilter.setEncoding("UTF-8");
        characterEncodingFilter.setForceEncoding(true);
        return new Filter[]{characterEncodingFilter};
    }
}
